<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            系统管理
        </li>
        <li>
            字典列表
        </li>
        <li>
            字典数据
        </li>
    </ul>
    <div>
        <input type="hidden" id="cupage" value="1"/>
        <input type="hidden" id="total" value="1"/>
        <input type="hidden" id="formurl" value="/manager/system/getDictDataPage"/>
    </div>
</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        字典
                    </h3>
                    <div class="btn-add-pikaqiu">
                        <button class="btn btn-xs" data-toggle="modal" data-target="#dictDataAddModal"><i class="icon-plus"></i> 添 加</button>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>字典类型</th>
                                <th>字典标签</th>
                                <th>字典键值</th>
                                <th>标签样式</th>
                                <th>字典描述</th>
                                <th>创建时间</th>
                                <th>创建人</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody id="loadData">

                            </tbody>
                        </table>
                        <!--#include file="/admin/include/page.html"-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="dictDataAddModal" tabindex="-1" role="dialog" aria-labelledby="dictTypeAddModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加字典数据</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <input type="hidden" id="dictDataId">
                    <div class="form-group">
                        <label for="dict_label" class="col-sm-2 control-label">字典标签</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="dict_label" placeholder="是">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="dict_value" class="col-sm-2 control-label">字典键值</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="dict_value" placeholder="1">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="css_class" class="col-sm-2 control-label">字典样式</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="css_class" placeholder="label-success">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="description" class="col-sm-2 control-label">字典描述</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="description" placeholder="请输字典描述">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addDictData()">提交更改</button>
            </div>
        </div>
    </div>
</div>


<script>
    $("#btn-load").on("click", function () {
        var a = $(this);
        a.button("loading");
        $("#cupage").val("1");
        loadData();
    });
    function loadData() {
        var dictType = GetQueryStringByLink($("#current_url_value").val(),'dictType');
        var para = {
            dictType: dictType
        };
        loadGetServer($("#formurl").val(), para, function (data) {
            var $loadData = $("#loadData");
            $loadData.html("");
            var list = data.page.list;
            var html_ = "";
            for (var i = 0; i < list.length; i++) {
                html_ += "<tr><td>" + list[i].dict_type + "</td><td>" + list[i].dict_label + "</td><td>" + list[i].dict_value + "</td>";
                html_ += "<td>" + list[i].css_class + "</td><td>" + list[i].description + "</td>";
                html_ += "<td>" + list[i].create_date + "</td><td>" + list[i].create_by + "</td>";
                if(list[i].status==0){
                    html_ += "<td><span class='label label-sm label-success'>正常</span></td>";
                }else{
                    html_ += "<td><span class='label label-sm label-warning'>异常</span></td>";
                }
                html_ += "<td><div class='hidden-sm hidden-xs btn-group'>";
                html_ += "<button class='btn btn-xs btn-info' title='修改字典数据' onclick='editDictData(" + list[i].id + ")'><i class='icon-pencil bigger-120'></i></button>";
                html_ += "<button class='btn btn-xs btn-warning' title='删除字典类型' onclick='showConfirm(" + list[i].id + ")'><i class='icon-trash bigger-120'></i></button>";
                html_ += "</div></td></tr>";
            }
            $loadData.html(html_);
            pageValue(data);
            pageData();
            $("#btn-load").button("reset");
        });
    }

    loadData();

    function addDictData(){
        var dictType = GetQueryStringByLink($("#current_url_value").val(),'dictType');
        var para = {
            dictType: dictType,
            dictDataId: $("#dictDataId").val(),
            dictLabel: $("#dict_label").val(),
            dictValue: $("#dict_value").val(),
            cssClass: $("#css_class").val(),
            description: $("#description").val()
        };
        loadGetServer('/manager/system/addDictData', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                alert('操作成功')
                $('#dictDataAddModal').modal('hide');
            }
            loadData();
        });
    }

    function editDictData(dictDataId){
        var para = {
            dictDataId: dictDataId
        };
        loadGetServer('/manager/system/getDictData', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                $('#dictDataAddModal').modal('show');
                $("#myModalLabel").html("编辑字典类型");
                $("#description").val(data.data.description);
                $("#dict_type").val(data.data.dict_type);
                $("#dict_label").val(data.data.dict_label);
                $("#dict_value").val(data.data.dict_value);
                $("#css_class").val(data.data.css_class);
                $("#dictDataId").val(data.data.id);
            }
            loadData();
        });
    }

    function deleteDictType(dictDataId){
        var para = {
            id: dictDataId
        };
        loadGetServer('/manager/system/deleteDictType', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                alert('操作成功')
            }
            loadData();
        });
    }

    function showConfirm(dictTypeId) {
        var r = confirm("是否确定删除此数据？");
        if (r == true) {
            deleteDictType(dictTypeId)
        }
    }

</script>